<?php

namespace app\admin\model\assess;

use think\Model;
use traits\model\SoftDelete;

class Point extends Model
{
	use SoftDelete;

    

    

    // 表名
    protected $name = 'assess_point';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    // 定义时间戳字段名
    protected $createTime = 'add_time';
    protected $updateTime = false;
    protected $deleteTime = 'delete_time';

    // 追加属性
    protected $append = [
        'relation_text',
        'add_time_text'
    ];

	public static function init(){
		self::afterDelete(function ($row){
			$row->is_del = 1;
			$row->save();
		});
	}

	public function getRelationList()
    {
        return ['本人' => __('本人'), '父亲' => __('父亲'), '母亲' => __('母亲'), '爷爷' => __('爷爷'), '奶奶' => __('奶奶'), '姥爷' => __('姥爷'), '姥姥' => __('姥姥'), '其他' => __('其他'), '咨询师' => __('咨询师')];
    }


    public function getRelationTextAttr($value, $data)
    {
        $value = $value ?: ($data['relation'] ?? '');
        $list = $this->getRelationList();
        return $list[$value] ?? '';
    }


    public function getAddTimeTextAttr($value, $data)
    {
        $value = $value ?: ($data['add_time'] ?? '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setAddTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }
}
